unit MenuWidget;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.ExtCtrls, MsgWidget, MenuItemWidget, Vcl.StdCtrls,
  Vcl.Imaging.pngimage;

type
  TfrMenu = class(TFrame)
    pnItem: TPanel;
    pnlg: TPanel;
    Bevel1: TBevel;
    Panel1: TPanel;
    lbtitle: TLabel;
    Image: TImage;
  private
    { Private declarations }
  public
    { Public declarations }

    procedure MenuCloseMSG(var msg: TMessage); message WM_CLOSEITEM_MSG;
    procedure setMenu();
    constructor Create(AOwner: TComponent); override;
    function addSubMenu: TfrMenuItem;
  end;

implementation


{$R *.dfm}

function TfrMenu.addSubMenu: TfrMenuItem;
var
  subitem: TfrMenuItem;
begin
  subitem := TfrMenuItem.Create(Self);
  subitem.Align := alTop;
  subitem.Parent := self.pnItem;
  Result := subitem;
end;

constructor TfrMenu.Create(AOwner: TComponent);
begin
  inherited;
  setMenu();
end;

procedure TfrMenu.MenuCloseMSG(var msg: TMessage);
var
  i: integer;
begin
  if msg.Msg = WM_CLOSEITEM_MSG then
  begin
    var subname := PChar(msg.LParam);

    for i := 0 to self.pnItem.ControlCount - 1 do
    begin
      if self.pnItem.Controls[i] is TfrMenuItem then
      begin
        if self.pnItem.Controls[i].Name <> subname then
          TfrMenuItem(self.pnItem.Controls[i]).init();
      end;
    end;
  end;
end;

procedure TfrMenu.setMenu;
var
  i: integer;
begin
  for i := 0 to self.pnItem.ControlCount - 1 do
  begin
    if self.pnItem.Controls[i] is TfrMenuItem then
    begin

      TfrMenuItem(self.pnItem.Controls[i]).init();
    end;
  end;
end;

end.

